package com.gitee.wsl.ext.number

fun Int.wrap(low: Int, high: Int): Int {
    val r = high - low
    var t = (this - low) % r
    if (t < 0) {
        t += r
    }
    return t + low
}

fun Long.wrap(low: Long, high: Long): Long {
    val r = high - low
    var t = (this - low) % r
    if (t < 0) {
        t += r
    }
    return t + low
}

fun Float.wrap(low: Float, high: Float): Float {
    val r = high - low
    var t = (this - low) % r
    if (t < 0) {
        t += r
    }
    return t + low
}

fun Double.wrap(low: Double, high: Double): Double {
    val r = high - low
    var t = (this - low) % r
    if (t < 0) {
        t += r
    }
    return t + low
}